<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java网络编程：URL与HttpURLConnection深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .info-card {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.05);
            position: relative;
            overflow: hidden;
        }
        
        .info-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 4px;
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-fadeInUp">
                Java网络编程核心技术
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 animate-fadeInUp" style="animation-delay: 0.2s;">
                深入理解URL与HttpURLConnection，掌握网络资源访问的精髓
            </p>
            <div class="flex justify-center space-x-6 animate-fadeInUp" style="animation-delay: 0.4s;">
                <div class="text-center">
                    <i class="fas fa-globe text-4xl mb-2"></i>
                    <p class="text-sm">网络通信</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-link text-4xl mb-2"></i>
                    <p class="text-sm">资源定位</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-download text-4xl mb-2"></i>
                    <p class="text-sm">数据传输</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        
        <!-- URL Introduction -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-8 text-center gradient-text">URL 统一资源定位符</h2>
            
            <div class="info-card mb-8">
                <p class="text-lg leading-relaxed mb-6">
                    <span class="drop-cap">U</span>RL（Uniform Resource Locator）是指向互联网资源的指针，它是网络编程中最基础也是最重要的概念之一。Java提供了强大的URL API，让我们能够轻松地进行网络通信和资源访问。
                </p>
                
                <div class="bg-gray-50 rounded-lg p-6 mb-6">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-code text-purple-600 mr-3"></i>
                        URL格式解析
                    </h3>
                    <div class="code-block">
                        <code>protocol :// hostname[:port] / path /[?query]</code>
                    </div>
                    <div class="mt-4 space-y-2">
                        <p class="text-gray-700"><i class="fas fa-arrow-right text-purple-600 mr-2"></i>示例1：http://localhost:8080/day28/register.html</p>
                        <p class="text-gray-700"><i class="fas fa-arrow-right text-purple-600 mr-2"></i>示例2：http://localhost:8080/day28/RegisterServlet?username=123&password=123</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- URL Creation Methods -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-hammer text-purple-600 mr-4"></i>
                URL对象的创建方式
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card-hover info-card">
                    <div class="feature-icon">
                        <i class="fas fa-link"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">方式一：绝对地址</h3>
                    <div class="code-block text-sm">
                        <code>URL url = new URL("http://www.baidu.com/qa/index.html");</code>
                    </div>
                    <p class="text-gray-600 mt-3">直接使用完整的URL字符串创建对象</p>
                </div>
                
                <div class="card-hover info-card">
                    <div class="feature-icon">
                        <i class="fas fa-sitemap"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">方式二：相对地址</h3>
                    <div class="code-block text-sm">
                        <code>URL base = new URL("http://www.baidu.com");<br>URL lib = new URL(base, "qa/index.html");</code>
                    </div>
                    <p class="text-gray-600 mt-3">基于基础URL创建相对路径的URL对象</p>
                </div>
                
                <div class="card-hover info-card">
                    <div class="feature-icon">
                        <i class="fas fa-puzzle-piece"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">方式三：组件构造</h3>
                    <div class="code-block text-sm">
                        <code>URL url = new URL("http", "www.baidu.com", "/qa/index.html");</code>
                    </div>
                    <p class="text-gray-600 mt-3">分别指定协议、主机和文件路径</p>
                </div>
                
                <div class="card-hover info-card">
                    <div class="feature-icon">
                        <i class="fas fa-server"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">方式四：完整参数</h3>
                    <div class="code-block text-sm">
                        <code>URL url = new URL("http", "www.baidu.com", 80, "/test/test.asp");</code>
                    </div>
                    <p class="text-gray-600 mt-3">包含端口号的完整构造方式</p>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- HttpURLConnection Section -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-8 text-center gradient-text">HttpURLConnection 深入解析</h2>
            
            <div class="info-card mb-8">
                <p class="text-lg leading-relaxed">
                    HttpURLConnection是Java标准库中用于HTTP通信的核心类，它继承自URLConnection，提供了对HTTP协议的完整支持。通过HttpURLConnection，我们可以向指定网站发送GET请求、POST请求，实现各种网络交互功能。
                </p>
                
                <div class="bg-purple-50 rounded-lg p-6 mt-6">
                    <h3 class="text-xl font-semibold mb-4">核心方法</h3>
                    <div class="code-block">
                        <code>public URLConnection openConnection() throws IOException</code>
                    </div>
                    <p class="text-gray-700 mt-3">
                        <i class="fas fa-info-circle text-purple-600 mr-2"></i>
                        返回一个URLConnection对象，表示到URL所引用的远程对象的<strong>连接</strong>
                    </p>
                </div>
            </div>
        </section>

        <!-- Relationship Diagram -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">类关系图</h2>
            <div class="info-card">
                <div class="mermaid">
                    graph TD
                        A[URL] -->|openConnection| B[URLConnection]
                        B --> C[HttpURLConnection]
                        C --> D[GET请求]
                        C --> E[POST请求]
                        C --> F[文件下载]
                        C --> G[数据上传]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <!-- Practical Cases -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-laptop-code text-purple-600 mr-4"></i>
                实战案例
            </h2>
            
            <div class="space-y-8">
                <div class="info-card">
                    <h3 class="text-2xl font-semibold mb-4 gradient-text">案例一：获取URL基本信息</h3>
                    <p class="text-gray-700 mb-4">通过URL对象的各种方法，我们可以获取URL的协议、主机、端口、路径等详细信息，这对于分析和处理网络资源非常有用。</p>
                    <div class="bg-gray-50 rounded-lg p-4">
                        <p class="text-sm text-gray-600">
                            <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                            提示：使用getProtocol()、getHost()、getPort()、getPath()等方法获取URL各部分信息
                        </p>
                    </div>
                </div>
                
                <div class="info-card">
                    <h3 class="text-2xl font-semibold mb-4 gradient-text">案例二：网络图片下载</h3>
                    <p class="text-gray-700 mb-4">使用URL和HttpURLConnection实现网络图片的下载功能，这是网络编程中最常见的应用场景之一。</p>
                    <div class="bg-blue-50 rounded-lg p-4 mb-4">
                        <p class="text-sm text-blue-800">
                            <i class="fas fa-download text-blue-600 mr-2"></i>
                            示例图片地址：http://i9.qhimg.com/dr/270_500_/t01628b7986e6a845b1.jpg
                        </p>
                    </div>
                </div>
                
                <div class="info-card">
                    <h3 class="text-2xl font-semibold mb-4 gradient-text">案例